### Alizade, Dancygier, Ditlmann 
### "National Penalties Reversed"
### Replication Code 
### Table C2
### For questions, contact jalizade@princeton.edu

# setup
rm(list = ls())
setwd("C:/Users/Jey/Dropbox/WZB/NaturalizationExperiment/Submission/JOP/replication_JOP/data")
library(readstata13)
dat <- read.dta13("data_survey2.dta")

# means
means_can <- sapply(names(dat)[grepl("can_", names(dat))], function(x) mean(dat[,x], na.rm=T))
means_turk <- sapply(names(dat)[grepl("turk_", names(dat))], function(x) mean(dat[,x], na.rm=T))
means_serb  <- sapply(names(dat)[grepl("serb_", names(dat))], function(x) mean(dat[,x], na.rm=T))

# standard deviations
sd_can <- sapply(names(dat)[grepl("can_", names(dat))], function(x) sd(dat[,x], na.rm=T))
sd_turk <- sapply(names(dat)[grepl("turk_", names(dat))], function(x) sd(dat[,x], na.rm=T))
sd_serb  <- sapply(names(dat)[grepl("serb_", names(dat))], function(x) sd(dat[,x], na.rm=T))

# differences-in-means
diff_turk_can <- means_turk - means_can
diff_turk_serb <- means_turk - means_serb

# p-values from t-tests (paired because within-subjects design)
vars <- c("culdist", "religiosity", "christians", "muslims", "education", "economic", "language", "warmth", "competence", "honesty", "integrate", "citizens_good", "citizens_usual", "discrim")
p_turk_can <- round(sapply(vars, function(x) t.test(dat[,paste0("turk_", x)], dat[,paste0("can_", x)], paired = T)$p.value), 3)
p_turk_serb <- round(sapply(vars, function(x) t.test(dat[,paste0("turk_", x)], dat[,paste0("serb_", x)], paired = T)$p.value), 3)

# put all in a data frame
tab <- data.frame(means_can, sd_can, means_turk, sd_turk, means_serb, sd_serb, diff_turk_can, p_turk_can, diff_turk_serb, p_turk_serb)
tab
